#ifndef TOOLS_H
#define TOOLS_H

#include <stdbool.h>
#include <stdint.h>
#include <time.h>

#define swap(a, b)                                                             \
  {                                                                            \
    typeof(a) t = a;                                                           \
    a = b;                                                                     \
    b = t;                                                                     \
  }
#define lengthof(a) (sizeof(a) / sizeof(a[0]))

#define DEBUG
#ifndef DEBUG
#define debug(fmt, ...)                                                        \
  do {                                                                         \
  } while (0)
#else
#define debug(fmt, ...)                                                        \
  do {                                                                         \
    printf("File:%s Line:%u Info:", __FILE__, __LINE__);                       \
    printf(fmt, ##__VA_ARGS__);                                                \
  } while ()

#endif // DEBUG

void clear_screen(void);

void clear_stdin(void);

char get_cmd(char start, char end, bool isshow);

bool get_str(char *str, size_t size);

char get_sex(void);

char *show_sex(char sex);

bool get_password(char *password, size_t min, size_t max, bool isshow);

void anykey_continue(void);

bool yes_or_no(void);

void show_msg(char *msg, float sec);

void show_err(char *err);

int init_id(const char *path, uint64_t arr[], size_t len);

uint64_t get_id(const char *path, size_t index);

size_t save_data(const char *path, void *data, size_t size, size_t nmemb);

size_t load_data(const char *path, void *data, size_t size, size_t nmemb);

size_t file_size(const char *path);

typedef enum Color {
    Black = 30, //黑色
    Red,        //红色
    Green,      //绿色
    Yellow,     //黄色
    Blue,       //蓝色
    Purple,     //紫色
    Cyan,       //青色
    White       //白色
} Color;

typedef enum Direct {
    Enter = 10,
    Esc = 27,
    Space = 32,
    Backsapce = 127,
    Up = 183,
    Down,
    Right,
    Left,
} Direct;

void print_color(const char *msg, Color color);

void show_cursor(void);

void hide_cursor(void);

void set_cursor(int x, int y);

//请自己确保分割后的数量不会超过大小
int split(char *src, char **dest, const char *separator);

size_t strlen_in_terminal(char *src);

size_t strlen_until_blank(char *src);

size_t str_count_space(char *src);

void time_add_days(struct tm *date, const int add_days);

void time_add_months(struct tm *date, const int add_months);

size_t number_len(int num);

char *itoa(int value, char *str, int radix);

char* time_now_str(char* str, int strlen);

#endif // TOOLS_H
